<?php 
/**
 * 维修model类
 * @Author    紫梦
 * @DateTime  2017-11-14
 * @copyright 响响租车
 * @version   1.0
 */
namespace app\common\model;
use think\Model;

class Repair extends Model
{
	protected $type = [
            'repair_date'  =>  'timestamp:Y-m-d',      
	        'bug_date'  =>  'timestamp:Y-m-d',      
	        'in_time'  =>  'timestamp:Y-m-d',      
	        'insure_time'  =>  'timestamp:Y-m-d',      
	        'shift_time'  =>  'timestamp:Y-m-d',      
	              
	    ];
    protected $insert = ['agency_id'];
    
    protected function setAgencyIdAttr()
    {
        return session('admin.agency_id');
    }    

	// 定义全局的查询范围
    protected static function base($query)
    {
    	$agency = session('admin.agency_id');
        if($agency==1){
            // $query->where('delete_time',null);

        }else{
            $query->where(['agency_id'=>$agency]);

        }
    		    	
    }

    public function repairFile()
    {
        return $this->hasMany('RepairFile','repair_id');
    }

    public function scopeStatus($query)
    {
        $query->where(['repair_status'=>1]);
    }
}